package com.ssm.subject.application.mq;

import com.alibaba.fastjson.JSON;
import com.ssm.subject.domain.bo.SubjectLikedBO;
import com.ssm.subject.domain.service.SubjectLikedDomainService;
import lombok.extern.log4j.Log4j2;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;


import javax.annotation.Resource;

@Component
@RocketMQMessageListener(topic = "subject-liked", consumerGroup = "subject-group")
@Log4j2
public class SubjectLikedConsumer implements RocketMQListener<String> {

    @Resource
    private SubjectLikedDomainService subjectLikedDomainService;

    @Override
    public void onMessage(String message) {
        log.info("SubjectLikedConsumer.onMessage.message:{}", message);
        SubjectLikedBO subjectLikedBO = JSON.parseObject(message, SubjectLikedBO.class);
        subjectLikedDomainService.syncLikedMsg(subjectLikedBO);
    }

}